import 'package:finance_app/src/entities/promo_code_entity.dart';

promoCodeEntityFromJson(PromoCodeEntity data, Map<String, dynamic> json) {
	if (json['id'] != null) {
		data.id = json['id'] is String
				? int.tryParse(json['id'])
				: json['id'].toInt();
	}
	if (json['name'] != null) {
		data.name = json['name'].toString();
	}
	if (json['code'] != null) {
		data.code = json['code'].toString();
	}
	if (json['discount_type'] != null) {
		data.discountType = json['discount_type'].toString();
	}
	if (json['discount_value'] != null) {
		data.discountValue = json['discount_value'] is String
				? num.tryParse(json['discount_value'])
				: json['discount_value'];
	}
	if (json['limit'] != null) {
		data.limit = json['limit'] is String
				? int.tryParse(json['limit'])
				: json['limit'].toInt();
	}
	if (json['limit_used'] != null) {
		data.limitUsed = json['limit_used'] is String
				? int.tryParse(json['limit_used'])
				: json['limit_used'].toInt();
	}
	if (json['expired_at'] != null) {
		data.expiredAt = json['expired_at'];
	}
	if (json['created_at'] != null) {
		data.createdAt = json['created_at'].toString();
	}
	if (json['updated_at'] != null) {
		data.updatedAt = json['updated_at'].toString();
	}
	if (json['deleted_at'] != null) {
		data.deletedAt = json['deleted_at'];
	}
	return data;
}

Map<String, dynamic> promoCodeEntityToJson(PromoCodeEntity entity) {
	final Map<String, dynamic> data = new Map<String, dynamic>();
	data['id'] = entity.id;
	data['name'] = entity.name;
	data['code'] = entity.code;
	data['discount_type'] = entity.discountType;
	data['discount_value'] = entity.discountValue;
	data['limit'] = entity.limit;
	data['limit_used'] = entity.limitUsed;
	data['expired_at'] = entity.expiredAt;
	data['created_at'] = entity.createdAt;
	data['updated_at'] = entity.updatedAt;
	data['deleted_at'] = entity.deletedAt;
	return data;
}